rm update
[EroBeats.git] / Djinn and Tonic - Erobeats / Menu.cpp
blob64e6c22fcb277aed9e7e3f8205011b6986c563dc
1 #include "menu.h"
2 #include "ScreenNames.h"
3 #include "RescourceKeys.h"
6 //create the animations, load the text and then play the music
8 Menu::Menu(int* scrs, FileIO* filePntr, ResourceMaster* resourcePointer)
10 hoverLevelSel = false;
11 hoversettings = false;
12 hovermusicRoom = false;
13 hoverQuit = false;
15 rsc = resourcePointer;
17 renderer = rsc->rendPtr;
18 screen = scrs;
20 outlineAnimation = new Animation(rsc->gameAnimations.at(WhiteBlueBG));
22 font = new Fonts(0, rsc);
24 int textSizeX = font->prcnt(0.20, 'x');
25 int textSizeY = font->prcnt(0.15, 'y');
26 int textAlignX = font->prcnt(0.75, 'x');
28 font->loadFont(SDL_Color{ 100,100,100,00 }, rsc->gameText.at(LevelSelectText), 2);
29 textLevelSelect = font->getTexture();
30 rectLevelSelect = {textAlignX, font->prcnt(0.05, 'y'), textSizeX , textSizeY };
32 font->loadFont(SDL_Color{ 100,100,100,00 }, rsc->gameText.at(SettingsText), 2);
33 textSettings = font->getTexture();
34 rectSettings = { textAlignX, font->prcnt(0.25, 'y'), textSizeX , textSizeY };
36 font->loadFont(SDL_Color{ 100,100,100,00 }, rsc->gameText.at(MusicRoomText), 2);
37 textMusicRoom = font->getTexture();
38 rectMusicRoom = { textAlignX, font->prcnt(0.45, 'y'), textSizeX , textSizeY };
40 font->loadFont(SDL_Color{ 100,100,100,00 }, rsc->gameText.at(QuitText), 2);
41 textQuit = font->getTexture();
42 rectQuit = { textAlignX, font->prcnt(0.65, 'y'), textSizeX , textSizeY };
44 rsc->bptr->playBGM();
45 gameLoop();
48 Menu::~Menu() {
52 void Menu::close()
54 delete font;
55 delete outlineAnimation;
56 destroyFonts();
59 void Menu::destroyFonts() {
60 SDL_DestroyTexture(textLevelSelect);
61 SDL_DestroyTexture(textSettings);
62 SDL_DestroyTexture(textMusicRoom);
63 SDL_DestroyTexture(textQuit);
66 void Menu::update()
68 hoverLevelSel = false;
69 hoversettings = false;
70 hovermusicRoom = false;
71 hoverQuit = false;
73 if (x > rectQuit.x && y > rectQuit.y) {
74 //cout << "ovr4\n";
75 hoverQuit = true;
77 else if (x > rectMusicRoom.x && y > rectMusicRoom.y) {
78 //cout << "ovr3\n";
79 hovermusicRoom = true;
81 else if (x > rectSettings.x && y > rectSettings.y) {
82 //cout << "ovr2\n";
83 hoversettings = true;
86 else if (x > rectLevelSelect.x && y > rectLevelSelect.y) {
87 //cout << "ovr1\n";
88 hoverLevelSel = true;
90 else {
91 ////cout << "notOvr\n";
92 hoverLevelSel = false;
93 hoversettings = false;
94 hovermusicRoom = false;
95 hoverQuit = false;
98 if (mouseClicked && hoverLevelSel) {
99 //cout << "Fired1\n";
100 running = false;
101 *screen = LevelSelectScreen;
103 else if (mouseClicked && hoversettings) {
104 //cout << "Fired2\n";
105 running = false;
106 *screen = SettingsScreen;
108 else if (mouseClicked && hovermusicRoom) {
109 running = false;
110 *screen = MusicRoomScreen;
112 else if (mouseClicked && hoverQuit) {
113 running = false;
114 *screen = Quit;
118 void Menu::play()
120 if (hoverLevelSel) {
121 hoverAddress = &hoverLevelSel;
123 else if (hoversettings) {
124 hoverAddress = &hoversettings;
126 else if (hovermusicRoom) {
127 hoverAddress = &hovermusicRoom;
129 else if (hoverQuit) {
130 hoverAddress = &hoverQuit;
133 if (mouseClicked && (hoverLevelSel || hoversettings || hovermusicRoom || hoverQuit)) {
134 rsc->sptr->playSFX(0);
137 if (!playedOnce && (hoverLevelSel || hoversettings || hovermusicRoom || hoverQuit) || hoverAddress != hoverAddressOld) {
138 rsc->sptr->playSFX(1);
139 playedOnce = true;
141 else if(playedOnce && (hoverLevelSel || hoversettings || hovermusicRoom || hoverQuit)){
142 playedOnce = true;
144 else {
145 playedOnce = false;
148 if (hoverLevelSel) {
149 hoverAddressOld = &hoverLevelSel;
151 else if (hoversettings) {
152 hoverAddressOld = &hoversettings;
154 else if (hovermusicRoom) {
155 hoverAddressOld = &hovermusicRoom;
157 else if (hoverQuit) {
158 hoverAddressOld = &hoverQuit;
163 void Menu::render()
165 SDL_RenderClear(renderer);
167 SDL_RenderCopy(renderer, rsc->gameBG.at(T1BG), NULL, NULL);
169 // SDL_Rect a = { 200,0,1000,1000 };
170 //SDL_RenderCopy(renderer, rsc->gameAnimations.at(1).at(2), NULL, &a);
172 if (hoverLevelSel) {
173 SDL_RenderCopy(renderer, outlineAnimation->itterateAnimation(60), NULL, &rectLevelSelect);
175 else if (hoversettings) {
176 SDL_RenderCopy(renderer, outlineAnimation->itterateAnimation(60), NULL, &rectSettings);
178 else if (hovermusicRoom) {
179 SDL_RenderCopy(renderer, outlineAnimation->itterateAnimation(60), NULL, &rectMusicRoom);
181 else if (hoverQuit) {
182 SDL_RenderCopy(renderer, outlineAnimation->itterateAnimation(60), NULL, &rectQuit);
185 SDL_RenderCopy(renderer, textLevelSelect, NULL, &rectLevelSelect);
186 SDL_RenderCopy(renderer, textSettings, NULL, &rectSettings);
187 SDL_RenderCopy(renderer, textMusicRoom, NULL, &rectMusicRoom);
188 SDL_RenderCopy(renderer, textQuit, NULL, &rectQuit);
191 SDL_RenderPresent(renderer);